/*
 *  HeartBeatController.cpp
 *  project8
 *
 *  Created by Luca Gobbo on 21-06-10.
 *  Copyright 2010 __MyCompanyName__. All rights reserved.
 *
 */

#include "HeartBeatController.h"


void HeartBeatController::run(){
    tzMAX = 180;
    tzMIN = 150;
	while (1) {
		if (infraredSensor.heartBeat()) {
                    beats++;
                    this->heartBeat();
		}
	}
}

void HeartBeatController::heartBeat(){
	this->led.on();
	mkt_busy_wait_us(100 MS); // moet vervangen worden door een timer met een callback
	this->led.off();
        if(beats >= 3){
            //bij timer tick hbCUR updaten en onderstaande code uitvoeren, dit kan mogelijk worden
            //gedaan in run.
            this->preAVG += hbCUR;
            this->hbAVG = this->preAVG / beats;
        }
}

void HeartBeatController::eraseData(){
    this->hbAVG = 0;
    this->hbCUR = 0;
    this->hbHIG = 0;
    this->beats = 0;
    this->preAVG = 0;
}

unsigned char HeartBeatController::getAVG(){
    return hbAVG;
}

unsigned char HeartBeatController::getCUR(){
    return hbCUR;
}

unsigned char HeartBeatController::getHIG(){
    return hbHIG;
}

void HeartBeatController::timeOut(){

}